import {BasicColumn, FormSchema} from '/@/components/Table';
import {render} from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: 'traceId',
    dataIndex: 'traceId',
    width: 140,
    align: 'left',
  },
  {
    title: '请求方式',
    dataIndex: 'requestMethod',
    width: 70,
  },
  {
    title: '操作人员',
    dataIndex: 'userName',
    width: 100,
  },
  {
    title: '操作地址',
    dataIndex: 'requestIp',
    width: 130,
  },
  {
    title: '业务模块',
    dataIndex: 'tag',
    width: 140,
    align: 'left',
  },
  {
    title: '操作类型',
    dataIndex: 'businessType',
    width: 100,
    customRender: ({ text }) => {
      return render.renderDict(text, 'log_business_type')
    },
  },
  {
    title: '操作摘要',
    dataIndex: 'summary',
    width: 110,
    align: 'left',
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 60,
    customRender: ({ text }) => {
      const color = text == '1' ? 'red' : text == '0'? 'green': 'gray';
      return render.renderTag(render.renderDict(text, 'access_status'),color)
    },
  },
  {
    title: '操作日期',
    dataIndex: 'createdAt',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'tag',
    label: '业务模块',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'traceId',
    label: 'traceId',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'userName',
    label: '操作人员',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'businessType',
    label: '类型',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'log_business_type',
      stringToNumber: true,
    },
    colProps: { span: 8 },
  },

  {
    field: 'status',
    label: '状态',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'access_status',
      stringToNumber: true,
    },
    colProps: { span: 8 },
  },
  {
    field: 'createdAt',
    component: 'RangePicker',
    label: '操作时间',
    colProps: {
      span: 8,
    },
  },
];

export const formDescSchema = [
  {
    field: 'tag',
    label: '业务模块'
  },
  {
    field: 'summary',
    label: '操作摘要'
  },
  
  {
    field: 'userName',
    label: '操作人员'
  },
  {
    field: 'businessType', 
    label: '操作类型',
    render: (curVal, data) => {
      return render.renderDict(curVal, 'log_business_type')
    },
  },
  {
    field: 'requestIp',
    label: '操作地址'
  },
  {
    field: 'location',
    label: '操作地点'
  },
  {
    field: 'traceId',
    label: 'traceId'
  },
  {
    field: 'requestMethod',
    label: '请求方式'
  },
  {
    field: 'method',
    label: '请求方法'
  },
  {
    field: 'requestUrl',
    label: '请求url'
  }, 
  {
    field: 'requestParam',
    label: '请求参数',
    contentStyle: {             
      maxWidth: '500px',
      wordBreak: 'break-all',
      wordWrap: 'break-word'
    },
    span: 1
  },
  {
    field: 'jsonResult',
    label: '响应结果',
    contentStyle: {             
      maxWidth: '500px',
      wordBreak: 'break-all',
      wordWrap: 'break-word'
    },
    span: 1
  },
  {
    field: 'errorMsg',
    label: '异常信息',
    contentStyle: {             
      maxWidth: '500px',
      wordBreak: 'break-all',
      wordWrap: 'break-word'
    }
  },
  {
    field: 'status',
    label: '操作状态',
    render: (curVal, data) => {
      const color = curVal == '1' ? 'red' : curVal == '0'? 'green': 'gray';
      return render.renderTag(render.renderDict(curVal, 'access_status'),color)
    },
  },
  {
    field: 'createdAt',
    label: '操作日期'
  }
];
